#include "includes.h"
#define STACKSIZE 512
INT32U Stack1[STACKSIZE];
INT32U Stack2[STACKSIZE];
INT32U Stack3[STACKSIZE];
INT32U StackMain[STACKSIZE];
//
//struct sigaction suspend;
//struct sigaction resume;

void task1(void *pd)
{
    sigaction(SIGINT,&suspend,0);
    sigaction(SIGQUIT,&resume,0);
        int i=0;
        int j;
        pd=pd;
        //usleep(10000);
        while(1)
        {
                //PC_DispStr(15, 8, "Task 1 is running", DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
                //
                //OSTimeDly(2000);
                //PC_DispStr(15, 8, "Task 1 is stopped", DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
                sleep(2);
                printf("tarsk 1\n");
                printf("%d\n",i);
                i++;
                if(i==3)
                {
                    OSTimeDly(150);
                    sleep(1);
                    i=0;
                    //OS_TaskStat();
                    
                    //printf("%d\n",OSCPUUsage);
                }
        }
}
void task2(void *pd)
{
    sigaction(SIGINT,&suspend,0);
    sigaction(SIGQUIT,&resume,0);
        int i=0;
        int j;
        pd=pd;
        while(1)
        {
                //PC_DispStr(15, 8, "Task 1 is running", DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
                //
                //OSTimeDly(2000);
                //PC_DispStr(15, 8, "Task 1 is stopped", DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
                sleep(1);
                printf("tarsk 2\n");
                printf("%d\n",i);
                i++;
                if(i==3)
                {
                    OSTimeDly(150);
                    sleep(1);
                    i=0;
                }

        }
}
void task3(void *pd)
{
    sigaction(SIGINT,&suspend,0);
    sigaction(SIGQUIT,&resume,0);
        int i;
        int j;
        pd=pd;
        while(1)
        {
                //PC_DispStr(15, 8, "Task 1 is running", DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
                //
                //OSTimeDly(2000);
                //PC_DispStr(15, 8, "Task 1 is stopped", DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
                sleep(1);
                printf("tarsk 3\n");
        }
}
void main(int argc, char *argv[])
{
        char Id1 = '1';
    char Id2 = '2';
    char Id3 = '3';

#if 0
    BSP_IntDisAll();                       /* For an embedded target, disable all interrupts until we are ready to accept them */
#endif

    OSInit();                              /* Initialize "uC/OS-II, The Real-Time Kernel"                                      */
        OSTaskCreate(task1,(void *)&Id1,Stack1,8);
        OSTaskCreate(task2,(void *)&Id2,Stack2,9);
        //OSTaskCreate(task3,(void *)&Id3,Stack3,10);

    OSStart();                             /* Start multitasking (i.e. give control to uC/OS-II) */
}


